// Domien Nowicki
#include "QtPixmapSprite.h"
#include <QPainter>

QtPixmapSprite::QtPixmapSprite(QtSprite *parent): QtSprite(parent), bounds(QRect(0,0,0,0)), autocenter(true), tiled(false)
{
}

QtPixmapSprite::~QtPixmapSprite()
{
}


QRectF QtPixmapSprite::boundingRect() const
{
	return bounds;
}

QPainterPath QtPixmapSprite::shape() const
{
	return shapepath;
}


void QtPixmapSprite::SetPixmap(const QPixmap& tile)
{
	pixmap = tile;
	bounds = pixmap.rect();

	QPainterPath path;
	path.addRect(bounds);
	shapepath = path;

	if (autocenter)
	{
		Center();
	}
}

void QtPixmapSprite::SetTiled(bool enabled)
{
	tiled = enabled;
}

void QtPixmapSprite::SetPixmapOffset(const QPoint& offset)
{
	tiled = true;
	pixmapOffset = offset;
	update();
}

const QPoint& QtPixmapSprite::PixmapOffset() const
{
	return pixmapOffset;
}

void QtPixmapSprite::SetWidth(unsigned int width)
{
	bounds.setWidth(width);
}

void QtPixmapSprite::SetHeight(unsigned int height)
{
	bounds.setHeight(height);
}


void QtPixmapSprite::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
{
	painter->setOpacity(Alpha());

	if (tiled)
	{
		painter->drawTiledPixmap(bounds, pixmap, pixmapOffset);
	}
	else
	{
		painter->drawPixmap(bounds, pixmap);
	}
}




